#include "StdAfx.h"
#include "DelayQueue.h"

DelayQueue::DelayQueue(void)
{
	index = 0;
}

DelayQueue::~DelayQueue(void)
{
	free(data);
}
bool DelayQueue::Add(float _Vcm, float _Vdf, unsigned int _Delay_ms)
{
	if(index+1==Max_index)
	{
		return false;
	}
	else
	{
		data[index].Vcm = _Vcm;
		data[index].Vdf = _Vdf;
		data[index].Delay_ms = _Delay_ms;
		data[index].delay_just_start = true;
		index++;
		return true;
	}
}

DelayTypeDef DelayQueue::Pop()
{
	if(index==0)
	{
		DelayTypeDef ERR;
		ERR.Vcm = 0;
		ERR.Vdf = 0;
		ERR.Delay_ms = -1;
		ERR.delay_just_start = false;
		return ERR;
	}
	else
	{
		DelayTypeDef out = data[0];
		for(int i=1;i<index;i++)
		{
			data[i-1].Vcm = data[i].Vcm;
			data[i-1].Vdf = data[i].Vdf;
			data[i-1].Delay_ms = data[i].Delay_ms;
			data[i-1].delay_just_start = true;
		}
		index--;
		return out;
	}
}

int DelayQueue::Index()
{
	return index;
}